import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-11-12
 * Time: 10:31
 */
public class Main {

    static class holdouman{
        int id;
        String name;

        public holdouman(int id, String name) {
            this.id = id;
            this.name = name;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            holdouman holdouman = (holdouman) o;
            return id == holdouman.id && Objects.equals(name, holdouman.name);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id, name);
        }

        @Override
        public String toString() {
            return id + "\t"+name;
        }
    }


    public static void main(String[] args) {
//        //set: treeset  hashset
//        //treeset
//        Set<Integer> set=new TreeSet<>();
//        //add
//        set.add(1);
//        set.add(25);
//        set.add(22);
//        //iterator的使用
//        Iterator<Integer> iterator=set.iterator();
//        for (Iterator<Integer> it = iterator; it.hasNext(); ) {
//            int a = it.next();
//            System.out.print(a+" ");
//        }
//        //remove
//        System.out.println(set.remove(25));
//        System.out.println(set.remove(5));
//        //size
//        System.out.println(set.size());
//        //contains
//        System.out.println(set.contains(1));
//        //clear
//        set.clear();
//        System.out.println(set.size());


//        //hashset 排序需要重写
//        Set<holdouman> sun=new HashSet<>();
//        sun.add(new holdouman(1,"蒋敦豪"));
//        sun.add(new holdouman(2,"鹭卓"));
//        sun.add(new holdouman(3,"李耕耘"));
//        sun.add(new holdouman(4,"李昊"));
//
//        Iterator<holdouman> iterator= sun.iterator();
//        for(Iterator<holdouman> it=iterator;it.hasNext();){
//            holdouman a=it.next();
//            System.out.println(a.toString());
//        }
//
//        System.out.println(sun.remove(new holdouman(3, "赵一博")));
//        System.out.println(sun.remove(new holdouman(5, "赵一博")));
//
//        System.out.println(sun.size());
//        System.out.println(sun.contains(new holdouman(1, "蒋敦豪")));


        //map : treemap hashmap
        Map<Integer,String> map=new HashMap<>();
        map.put(6,"卓沅");
        map.put(7,"赵小童");
        map.put(8,"何浩楠");
        map.put(6,"赵小童");

        //key是唯一的,后面put相同的key，相当于把前面的数据删除，添加新的数据
        System.out.println(map.get(6));
        System.out.println(map.size());//size=3

        System.out.println(map.get(1));
        System.out.println(map.get(7));
        System.out.println(map.getOrDefault(4, "利好"));

        map.forEach((key,value)-> System.out.println(key+"\t"+value));
        System.out.println();

        map.replace(6,"卓沅");
        Set<Map.Entry<Integer,String>> set=map.entrySet();
        Iterator<Map.Entry<Integer,String>> iterator=set.iterator();
        for(Iterator<Map.Entry<Integer,String>> it=iterator;it.hasNext();){
            Map.Entry<Integer,String> a=it.next();
            System.out.println(a.getKey()+"\t"+a.getValue());
        }

        System.out.println("************");
        Set<Integer> set1=map.keySet();
        Collection<String> a=map.values();

        System.out.println(set1);
        System.out.println(a);
        System.out.println("************");

        //将集合的元素添加到set中达到去的效果addAll
        Set<Integer> set2 =new HashSet<>();
        set2.addAll(set1);
        System.out.println(set2);
        System.out.println(set2.containsAll(set1));

    }
}